/**
 * @file
 * @author dousha
 * @date 2020
 */

#include "bits.h"

void bits_set(uint8_t *bits, uint32_t offset) {
	uint32_t byteOffset = offset / 8;
	uint32_t inByteOffset = offset - byteOffset * 8;
	bits[byteOffset] |= (1u << inByteOffset);
}

void bits_clear(uint8_t *bits, uint32_t offset) {
	uint32_t byteOffset = offset / 8;
	uint32_t inByteOffset = offset - byteOffset * 8;
	bits[byteOffset] &= ~(1u << inByteOffset);
}

void bits_set_range(uint8_t *bits, uint32_t offset, uint32_t len) {
	for (uint32_t i = 0; i < len; i++) {
		bits_set(bits, offset + i);
	}
}

void bits_clear_range(uint8_t *bits, uint32_t offset, uint32_t len) {
	for (uint32_t i = 0; i < len; i++) {
		bits_clear(bits, offset + i);
	}
}
